package com.ruoyi.info.service.impl;

import java.util.List;

import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.info.mapper.CmsNavMapper;
import com.ruoyi.info.domain.CmsNav;
import com.ruoyi.info.service.ICmsNavService;
import com.ruoyi.common.core.text.Convert;

/**
 * 导航栏Service业务层处理
 * 
 * @author xwj
 * @date 2023-07-06
 */
@Service
public class CmsNavServiceImpl implements ICmsNavService 
{
    @Autowired
    private CmsNavMapper cmsNavMapper;

    /**
     * 查询导航栏
     * 
     * @param id 导航栏主键
     * @return 导航栏
     */
    @Override
    public CmsNav selectCmsNavById(Long id)
    {
        return cmsNavMapper.selectCmsNavById(id);
    }

    /**
     * 查询导航栏列表
     * 
     * @param cmsNav 导航栏
     * @return 导航栏
     */
    @Override
    public List<CmsNav> selectCmsNavList(CmsNav cmsNav)
    {
        return cmsNavMapper.selectCmsNavList(cmsNav);
    }

    /**
     * 查询导航栏 - 缓存
     * @param param
     * @return
     */
    @Override
    public List<CmsNav> selectCmsNavListCache(CmsNav param, String key) {
        Object obj = CacheUtils.get(key);
        List<CmsNav> list = null;
        if(obj != null) {
            list = StringUtils.cast(obj);
        } else {
            list = cmsNavMapper.selectCmsNavList(param);

            if(list != null && !list.isEmpty()) {
                CacheUtils.put(key, list);
            }
        }

        return list;
    }

    /**
     * 新增导航栏
     * 
     * @param cmsNav 导航栏
     * @return 结果
     */
    @Override
    public int insertCmsNav(CmsNav cmsNav)
    {
        cmsNav.setCreateTime(DateUtils.getNowDate());
        return cmsNavMapper.insertCmsNav(cmsNav);
    }

    /**
     * 修改导航栏
     * 
     * @param cmsNav 导航栏
     * @return 结果
     */
    @Override
    public int updateCmsNav(CmsNav cmsNav)
    {
        cmsNav.setUpdateTime(DateUtils.getNowDate());
        return cmsNavMapper.updateCmsNav(cmsNav);
    }

    /**
     * 批量删除导航栏
     * 
     * @param ids 需要删除的导航栏主键
     * @return 结果
     */
    @Override
    public int deleteCmsNavByIds(String ids)
    {
        return cmsNavMapper.deleteCmsNavByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除导航栏信息
     * 
     * @param id 导航栏主键
     * @return 结果
     */
    @Override
    public int deleteCmsNavById(Long id)
    {
        return cmsNavMapper.deleteCmsNavById(id);
    }


}
